import {
    OrderListAxios, AddOrderDayAxios, AddOrderWeekAxios, AddOrderMonthAxios, SearchOrderAxios, ShowOrderGoodsAxios
} from "../../http/apis/orderApi"
import { timeFormat } from '../../utils/utils'

export default {

    // 订单列表
    getOrderInfoAction(context, params) {
        return new Promise((resolve, reject) => {
            OrderListAxios(params).then(res => {
                if (res.data.code === 200) {
                    console.log("获取订单列表数据请求成功", res.data.data[1]);
                    let arr = res.data.data[1];
                    let dataArr = []
                    arr.forEach((item) => {
                        let obj = {
                            customer_name: item.customer_name,
                            order_id: item.order_id,
                            customer_Id: item.customer_Id,
                            contact_id:item.contact_id,
                            contact_name: item.contact_name,
                            order_date: timeFormat(item.order_date),
                            Submit_order_date: timeFormat(item.Submit_order_date),
                            order_amount: item.order_amount,
                            order_received: item.order_received,
                            consignee:item.consignee,
                            consignee_phone:item.consignee_phone,
                            consignee_address:item.consignee_address,
                            order_debt: item.order_debt,
                            order_status: item.order_status,
                            shipping_status: item.shipping_status,
                            order_remark: item.order_remark,
                            employee_name: item.employee_name,
                            enter_time: timeFormat(item.enter_time),
                            accessory: "附件详情",
                            ordergoods: "商品详情",
                        };
                        dataArr.push(obj)

                    })
                    resolve({ dataArr, totalSize: res.data.data[0] })
                } else {
                    reject({
                        code: res.data.code,
                        msg: res.data.msg
                    })
                }
            })
        })
    },

    // 今日新增
    getOrderDayInfoAction(context, params) {
        return new Promise((resolve, reject) => {
            AddOrderDayAxios(params).then(res => {
                if (res.data.code === 200) {
                    console.log("获取今日新增订单列表数据请求成功", res.data.data);
                    let arr = res.data.data[0];
                    let dataArr = []
                    arr.forEach((item) => {
                        let obj = {
                            customer_name: item.customer_name,
                            order_id: item.order_id,
                            customer_Id: item.customer_Id,
                            contact_id:item.contact_id,
                            contact_name: item.contact_name,
                            order_date: timeFormat(item.order_date),
                            Submit_order_date: timeFormat(item.Submit_order_date),
                            order_amount: item.order_amount,
                            order_received: item.order_received,
                            consignee:item.consignee,
                            consignee_phone:item.consignee_phone,
                            consignee_address:item.consignee_address,
                            order_debt: item.order_debt,
                            order_status: item.order_status,
                            shipping_status: item.shipping_status,
                            order_remark: item.order_remark,
                            employee_name: item.employee_name,
                            enter_time: timeFormat(item.enter_time),
                            accessory: "附件详情",
                            ordergoods: "商品详情",
                        };
                        dataArr.push(obj)
                    })
                    resolve({ dataArr, totalSize: res.data.data[1] })
                } else {
                    reject({
                        code: res.data.code,
                        msg: res.data.msg
                    })
                }
            })
        })
    },

    // 本周新增
    getOrderWeekInfoAction(context, params) {
        return new Promise((resolve, reject) => {
            AddOrderWeekAxios(params).then(res => {
                if (res.data.code === 200) {
                    console.log("获取本周新增订单列表数据请求成功", res.data.data);
                    let arr = res.data.data[0];
                    let dataArr = []
                    arr.forEach((item) => {
                        let obj = {
                            customer_name: item.customer_name,
                            order_id: item.order_id,
                            customer_Id: item.customer_Id,
                            contact_name: item.contact_name,
                            contact_id:item.contact_id,
                            order_date: timeFormat(item.order_date),
                            Submit_order_date: timeFormat(item.Submit_order_date),
                            order_amount: item.order_amount,
                            order_received: item.order_received,
                            consignee:item.consignee,
                            consignee_phone:item.consignee_phone,
                            consignee_address:item.consignee_address,
                            order_debt: item.order_debt,
                            order_status: item.order_status,
                            shipping_status: item.shipping_status,
                            order_remark: item.order_remark,
                            employee_name: item.employee_name,
                            enter_time: timeFormat(item.enter_time),
                            accessory: "附件详情",
                            ordergoods: "商品详情",
                        };
                        dataArr.push(obj)
                    })
                    resolve({ dataArr, totalSize: res.data.data[1] })
                } else {
                    reject({
                        code: res.data.code,
                        msg: res.data.msg
                    })
                }
            })
        })
    },

    // 获取本月新增
    getOrderMonthInfoAction(context, params) {
        return new Promise((resolve, reject) => {
            AddOrderMonthAxios(params).then(res => {
                if (res.data.code === 200) {
                    console.log("获取本月新增订单列表数据请求成功", res.data.data);
                    let arr = res.data.data[0];
                    let dataArr = []
                    arr.forEach((item) => {
                        let obj = {
                            customer_name: item.customer_name,
                            order_id: item.order_id,
                            customer_Id: item.customer_Id,
                            contact_name: item.contact_name,
                            contact_id:item.contact_id,
                            order_date: timeFormat(item.order_date),
                            Submit_order_date: timeFormat(item.Submit_order_date),
                            order_amount: item.order_amount,
                            order_received: item.order_received,
                            consignee:item.consignee,
                            consignee_phone:item.consignee_phone,
                            consignee_address:item.consignee_address,
                            order_debt: item.order_debt,
                            order_status: item.order_status,
                            shipping_status: item.shipping_status,
                            order_remark: item.order_remark,
                            employee_name: item.employee_name,
                            enter_time: timeFormat(item.enter_time),
                            accessory: "附件详情",
                            ordergoods: "商品详情",
                        };
                        dataArr.push(obj)
                    })
                    resolve({ dataArr, totalSize: res.data.data[1] })
                } else {
                    reject({
                        code: res.data.code,
                        msg: res.data.msg
                    })
                }
            })
        })
    },

    // 订单列表搜索
    SearchOrderAction(context, params) {
        return new Promise((resolve, reject) => {
            SearchOrderAxios(params).then(res => {
                if (res.data.code === 200) {
                    console.log("获取搜索列表数据请求成功", res.data.data[1]);
                    let arr = res.data.data[1];
                    let dataArr = []
                    arr.forEach((item) => {
                        let obj = {
                            customer_name: item.customer_name,
                            order_id: item.order_id,
                            customer_Id: item.customer_Id,
                            contact_name: item.contact_name,
                            contact_id:item.contact_id,
                            order_date: timeFormat(item.order_date),
                            Submit_order_date: timeFormat(item.Submit_order_date),
                            order_amount: item.order_amount,
                            order_received: item.order_received,
                            consignee:item.consignee,
                            consignee_phone:item.consignee_phone,
                            consignee_address:item.consignee_address,
                            order_debt: item.order_debt,
                            order_status: item.order_status,
                            shipping_status: item.shipping_status,
                            order_remark: item.order_remark,
                            employee_name: item.employee_name,
                            enter_time: timeFormat(item.enter_time),
                            accessory: "附件详情",
                            ordergoods: "商品详情",
                        };
                        dataArr.push(obj)
                    })
                    resolve({ dataArr, totalSize: res.data.data[0] })
                } else {
                    reject({
                        code: res.data.code,
                        msg: res.data.msg
                    })
                }
            })
        })
    },

    // 订单商品详情
    OrderGoodsInfoAction(context, params) {
        return new Promise((resolve, reject) => {
            ShowOrderGoodsAxios(params).then(res => {
                if (res.data.code === 200) {
                    console.log("获取订单商品详情数据请求成功", res.data);
                    resolve(res)
                } else {
                    reject({
                        code: res.data.code,
                        msg: res.data.msg
                    })
                }
            })
        })
    },
}